<template>
	<body-wrap :isFlex='true' :showLoading="false">
		<view class="detailtopbox">
			<image class="dimg" :src="details.imageUrl" mode="widthFix"></image>
		</view>
		<view class="detaiMain">
			<view class="title">{{details.name}}</view>
			<view class="content" v-html="details.content"></view>
		</view>
		<template v-slot:footer>
			<view class="llffbotbox">
				<template v-if="details.topCategoryId==14">
					<view class="btn" @click="openPop(1)">需要服务</view>
					<!-- <view class="btn" @click="openPop(2)">成为志愿者</view> -->
					<view class="btn" @click="volunteer(2)">成为志愿者</view>
				</template>
				<template v-else>
					<view class="btn" @click="openPop('')">我要加入</view>
				</template>
			</view>
		</template>
		<uni-popup ref="popup">
			<add-form @complete="close" :id="details.id" :topCtgId="details.topCategoryId" :aidOrderType="aidOrderType"/>
		</uni-popup>
	</body-wrap>
	
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import bodyWrap from "@/components/bodyWrap/index.vue"
	import addForm from '../components/addForm.vue'
	import {getStorage,toast} from "@/utils/common.js"
	export default defineComponent({
		components:{
			bodyWrap,
			addForm
		},
		props:{
			
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				userInfo:computed(()=>store.state.base.userInfo), 
				id:'',
				imgUrlPrefix:getApp().globalData.imgUrlPrefix,
				details:{},
				aidOrderType:''  // 1需要服务，2成为志愿者
			})
			
			onLoad(options=>{
				// if(options && options.id){
				// 	state.id = options.id
				// }
				
			})
			
			state.details = JSON.parse(getStorage('keepDetails') || '{}')
			onMounted(()=>{
				
			})
			
			const openPop = (type)=>{
				state.aidOrderType = type
				proxy.$refs.popup.open('bottom')
			}
			
			const close = ()=> {
				proxy.$refs.popup.close()
			}
			
			const volunteer = ()=>{
				if(state.userInfo.volunteerFlag==1){
					return toast('您已经是志愿者了！')
				}
				uni.showModal({
					title: '提示',
					content: '确定成为志愿者吗？',
					success: async (res)=> {
						if (res.confirm) {
							const rt = await saveMemberInfo({volunteerFlag:1})
							if(rt.code==0){
								toast('恭喜，您已成为志愿者！')
								store.commit('base/set_userInfo',{volunteerFlag:1})
							}
						} else if (res.cancel) {
							//console.log('用户点击取消');
						}
					}
				});
			}
			
			return {
				...toRefs(state),
				openPop,
				close,
				volunteer
			}
		}
	})
</script>

<style lang="scss" scoped>
	.detailtopbox{
		width: 100%;
		max-height: 500rpx;
		overflow: hidden;
		.dimg{
			display: block;
			width: 100%;
		}
	}
	.detaiMain{
		background: #fff;
		border-top-left-radius: 50rpx;
		border-top-right-radius: 50rpx;
		min-height: 1000rpx;
		margin: -50rpx 0 0 0;
		padding: 50rpx 30rpx 30rpx 30rpx;
		.title{
			font-size: 40rpx;
			line-height: normal;
			font-weight: bold;
			text-align: center;
		}
		.content{
			font-size: 32rpx;
			font-weight: bold;
			padding: 30rpx 0 0 0;
			text-indent: 56rpx;
			line-height: 64rpx;
		}
	}
	.llffbotbox{
		padding: 30rpx;
		.btn{
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			font-size: 34rpx;
			border-radius: 40rpx;
			background: #fba70e;
			color: #fff;
			&+.btn{
				margin-top: 20rpx;
			}
		}
	}
</style>
